import { Badge, Button, Popconfirm, Space, TableColumnsType, Tag, Tooltip, Typography } from 'antd'
import { NavigateFunction } from 'react-router-dom'
import type { ITableData, ITableDataRoleList } from './types'
import { DIS_STATUSBANDBTNTEXT, STATUSBAND, USERTYPETEXT } from '@/constant'
import PermissionLink from '@/components/PermissionLink'
export const useIndexColumns = (
  onEdit: (info: ITableData) => void,
  resetPwd: (id: number) => void,
  params: Record<string, any>,
  onStatus: (info: ITableData) => void,
  navigate: NavigateFunction,
): TableColumnsType<ITableData> => [
  {
    title: '组织名称',
    dataIndex: 'orgName',
    key: 'orgName',
    align: 'center',
    width: 200,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '工号',
    dataIndex: 'workId',
    key: 'workId',
    align: 'center',
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '用户名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '手机号',
    dataIndex: 'phone',
    key: 'phone',
    align: 'center',
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '用户类型',
    dataIndex: 'type',
    key: 'type',
    align: 'center',
    render: (info) => {
      return USERTYPETEXT[info] || '-'
    },
  },
  {
    title: '用户状态',
    dataIndex: 'status',
    key: 'status',
    align: 'center',
    render: (info) => {
      return <Badge status={info == 1 ? 'success' : 'error'} text={STATUSBAND[info] || '-'} />
    },
  },
  {
    fixed: 'right',
    title: '操作',
    width: 250,
    align: 'center',
    render: (info) => {
      return (
        <Space size="large">
          <PermissionLink permission="editUser" onClick={() => onEdit(info)}>
            编辑
          </PermissionLink>
          <PermissionLink permission="detailUser" onClick={() => navigate('/system/user/detail?id=' + info.id)}>
            详情
          </PermissionLink>
          <Popconfirm title={`确认重置密码吗？`} onConfirm={() => resetPwd(info.id)} okText="确认" cancelText="取消">
            <PermissionLink permission="resetPsw">重置密码</PermissionLink>
          </Popconfirm>
          <Popconfirm
            title={`确认${DIS_STATUSBANDBTNTEXT[info.status]}吗？`}
            onConfirm={() => onStatus(info)}
            okText="确认"
            cancelText="取消"
          >
            <PermissionLink permission="offUser" type={info.status == 1 ? 'danger' : undefined}>
              {DIS_STATUSBANDBTNTEXT[info.status]}
            </PermissionLink>
          </Popconfirm>
        </Space>
      )
    },
  },
]
export const useRoleColumns = (): TableColumnsType<ITableDataRoleList> => [
  {
    width: 150,
    title: '所属应用',
    dataIndex: 'applicationName',
    key: 'applicationName',
    align: 'center',
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return <Tooltip title={info}>{info}</Tooltip>
    },
  },
  {
    width: 150,
    title: '角色名称',
    dataIndex: 'roleName',
    key: 'roleName',
    align: 'center',
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return <Tooltip title={info}>{info}</Tooltip>
    },
  },
]
export const useRoleColumnsDel = (onDel: (info: ITableDataRoleList) => void): TableColumnsType<ITableDataRoleList> => [
  {
    width: 150,
    title: '所属应用',
    dataIndex: 'applicationName',
    key: 'applicationName',
    align: 'center',
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return <Tooltip title={info}>{info}</Tooltip>
    },
  },
  {
    width: 150,
    title: '角色名称',
    dataIndex: 'roleName',
    key: 'roleName',
    align: 'center',
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return <Tooltip title={info}>{info}</Tooltip>
    },
  },
  {
    title: '操作',
    fixed: 'right',
    width: 100,
    align: 'center',
    render: (info) => {
      return (
        <Space size="large">
          <PermissionLink permission="deleteRole" onClick={() => onDel(info)}>
            删除
          </PermissionLink>
        </Space>
      )
    },
  },
]
